/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ucm;

import java.sql.ResultSet;
import sql.SELECT_SQL;
import view.DomeMain_View;

/**
 *
 * @author 马凯
 */
public class StudentCard_UC {

    private static StudentCard_UC suc;
    private DomeMain_View dmv;
    private String cid;

    public static StudentCard_UC getInstance(DomeMain_View dmv) {
        if (suc == null) {
            suc = new StudentCard_UC();
            suc.dmv = dmv;
        } else {
            suc.dmv = dmv;
        }
        return suc;
    }

    public void run() {
        cid = dmv.getViewModel().getCid_TF().getText();
        String sqlQuery = "SELECT dormitory FROM roll WHERE card_id='" + cid + "';";
        ResultSet rs = SELECT_SQL.getInstance().run(sqlQuery);
        try {
            if (rs.first()) {
                if (rs.getString("dormitory").equals("N/A")) {
                    this.dmv.getViewModel().getCheckPicture_La1().setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\马凯\\My Documents\\ok.jpg"));
                } else {
                    this.dmv.getViewModel().getCheckPicture_La1().setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\马凯\\My Documents\\denied.jpg"));
                }
            //sqlQuery = "SELECT * FROM rfid WHERE cid='" + cid + "' and password = '" + psw + "';";
            } else {
                this.dmv.getViewModel().getCheckPicture_La1().setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\马凯\\My Documents\\denied.jpg"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
